package skdao

import (
	"Cgo/backend/models"
	"Cgo/global"
)

type tjDao struct{}

var TjDao = tjDao{}

// GetRecommendedBooks 获取推荐图书列表
func (tj tjDao) GetRecommendedBooks() ([]models.SkBook, error) {
	var recommendedBooks []models.SkBook

	// 查询 sk_tuijian 表中 bookId 与 sk_book 表中 bookId 相同的所有图书数据
	if err := global.DB.Table("sk_tuijian").
		Joins("JOIN sk_book ON sk_tuijian.bookId = sk_book.bookid").
		Find(&recommendedBooks).Error; err != nil {
		return nil, err
	}

	return recommendedBooks, nil
}
